package ${basePackage}.controller;

import ${basePackage}.service.I${modelNameUpperCamel}Service;

import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;

import com.kqzz.common.api.response.Response;
import ${basePackage}.bean.${modelNameUpperCamel};
import com.kqzz.common.api.request.ListRequest;
import com.github.pagehelper.PageInfo;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

/**
* @Description
* @author ${author}
* @date ${date}
*/
@Slf4j
@Api(tags = "${modelNameUpperCamel}控制器")
@RestController
@RequestMapping("${baseRequestMapping}")
public class ${modelNameUpperCamel}Controller {
@Autowired
private I${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

@ApiOperation(value="保存")
@PostMapping("/save")
public Response add(@ApiParam(value = "请求对象", required = true) @RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
try {
${modelNameLowerCamel}Service.saveNotNull(${modelNameLowerCamel});
return new Response().success();
} catch (Exception e) {
log.error("保存异常：",e);
return new Response().failure();
}
}

@ApiOperation(value="删除")
@PostMapping("/delete")
public Response delete(@ApiParam(value = "主键ID {'id':''}", required = true) @RequestBody Map<String,String> map) {
try {
${modelNameLowerCamel}Service.deleteLogic(map.get("id"));
return new Response().success();
} catch (Exception e) {
log.error("删除异常：",e);
return new Response().failure();
}
}

@ApiOperation(value="更新")
@PostMapping("/update")
public Response update(@ApiParam(value = "请求对象", required = true) @RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
try {
${modelNameLowerCamel}Service.updateNotNull(${modelNameLowerCamel});
return new Response().success();
} catch (Exception e) {
log.error("删除异常：",e);
return new Response().failure();
}
}

@ApiOperation(value="查看详情")
@PostMapping("/detail")
public Response detail(@ApiParam(value = "主键ID {'id':''}", required = true) @RequestBody Map<String,String> map) {
${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.selectByKey(map.get("id"));
return new Response().success(${modelNameLowerCamel});
}

@ApiOperation(value="分页列表")
@PostMapping("/list")
public Response list(@ApiParam(value = "请求对象", required = true) @RequestBody ListRequest pojo) {
Example example = new Example(${modelNameUpperCamel}.class);
PageInfo<${modelNameUpperCamel}> pgList = ${modelNameLowerCamel}Service.selectAll(example, pojo.getCurrentPage(), pojo.getPageSize());
return new Response().success(pgList);
}
}
